<?php
/**
 * Description of TitleSong
 *
 * @author Pouja
 */
class Track {
    private $id;
    private $name;
    private $album;
    private $rating;
    private $youtube;
    private $listened;

    /**
     * Constructor
     */
    public function Track(){

    }
    /**
     * Returns the id of the track
     * @return int The id of the track 
     */
    public function id(){
        return $this->id;
    }
    /**
     * Sets the id of the track
     * @param int $id The id of the track
     */
    public function setID($id){
        $this->id=$id;
    }

    /**
     * Sets the rating of the track given by an user
     * @param int $rating The rating of the track
     */
    public function setRating($rating){
        $this->rating=$rating;
    }

    /**
     * Sets the listen count of the track
     * @param int $listened The listen count
     */
    public function setListened($listened){
        $this->listened=$listened;
    }

    /**DEPRECATED
     * Sets to which album this track belongs
     * @param Album $album The album in which this track is in
     */
    public function setAlbum($album){
        if($album instanceof Album){
            $this->album=$album;
        }
    }
    
    /**DEPRECATED
     * Returns the album in which this track is in
     * @return Album $album The album 
     */
    public function album(){
        return $this->album;
    }
    
    /**
     * Returns the name of the track
     * @return String $name The name of the track
     */
    public function name(){
        return $this->name;
    }
    
    /**DEPRECATED
     * Return the id the Artist to which this track belongs
     * @return int id The id of an artist
     */
    public function artist(){
        return $this->artistID;
    }
    
    /**
     * Returns the youtube id of matching track video
     * @return String youtube id
     */
    public function youtube(){
        return $this->youtube;
    }
    
    /**DEPRECATED
     * Returns the release info of this track
     * @return String $releaseinfo the release info
     */
    public function releaseInfo(){
        return $this->releaseInfo;
    }
    
    /**
     * Returns the listen count of this track
     * @return int listen count
     */
    public function listened(){
        return $this->listened;
    }
    
    /**
     * Sets the name of the track
     * @param String $name The name of the track
     */
    public function setName($name){
        $this->name=$name;
    }
    
    /**DEPRECATED
     * Sets the id of the matching artist
     * @param type $artistID The id of the artist
     */
    public function setArtistID($artistID){
        $this->artistID=$artistID;
    }
    
    /**
     * Sets the youtube id of the matching track video
     * @param String $youtubeLink the youtube id
     */
    public function setYoutube($youtubeLink){
        $this->youtube=$youtubeLink;
    }
    
    /**DEPRECATED
     * Sets the release info of this track
     * @param String $info the release info of this track
     */
    public function setReleaseInfo($info){
        $this->releaseInfo=$info;
    }
    
    /**
     * Increases the listen count
     */
    public function addListener(){
        if($this->listened==NULL){
            $this->listened=0;
        }
        $this->listened++;
    }
    
    /**DEPRECATED
     * Equals, returns true if the track is an instance of Track and the artist are the same
     * @param Track $that the track to be tested
     * @return boolean true if the artist are the same, false otherwise 
     */
    public function equals($that){
        if($that instanceof Track){
            if($that->artist->equals($this->artist) && strcmp($that->name(),$this->name)==0){
                return true;
            }
        }
        return false;
    }
    
    /**
     * Returns a string representation of this object
     * @return string String representation
     */
    public function toString(){
        $out='TitleSong[';
        $out.=$this->name().',';
        $out.=$this->listened().',';
        $out.=$this->releaseInfo().',';
        $out.=$this->listened().',';
        $out.=$this->youtube().',';
        $out.=']';
        return $out;
    }
    
    /**
     * Returns a representation of the object in array format, so it can be parsed to JSON string
     * @return Array an array representation 
     */
    public function toJSON(){
        $out=array();
        $out['name']=$this->name;
        $out['listened']=$this->listened;
        $out['youtube']=$this->youtube;
        $out['id']=$this->id;
        $out['rating']=$this->rating;
        return $out;
    }
}

?>
